/* $Id: ContestsServlet.java 133 2011-08-26 12:01:00Z altdotua@gmail.com $ */

package alt.djudge.frontend.server.servlets;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import alt.djudge.frontend.server.datatypes.AbstractEntry;
import alt.djudge.frontend.server.models.ContestsModel;
import alt.djudge.frontend.server.models.CoreInterface;


public class ContestsServlet extends AbstractDataServlet
{
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unused")
	private static final Logger log = Logger.getLogger(ContestsServlet.class);
	
	@Override
	protected CoreInterface<? extends AbstractEntry> getModel()
	{
		return ContestsModel.getCore();
	}

	@Override
	protected void processAction(HttpServletRequest req, HttpServletResponse resp) throws IOException
	{
		/*
        ContestEntry contest = ContestsModel.getEntry(id);
        if ("customEdit".equalsIgnoreCase(action) && contest != null && model.canEdit(user))
        {
        	boolean fAllowAllLanguages = null != req.getParameter("AllowAllLanguages");
        	boolean fAllowAllUsers = null != req.getParameter("AllowAllUsers");
        	boolean fAllowFirstTestOnly = null != req.getParameter("AllowFirstTestOnly");
        	String contestType = req.getParameter("ContestType");
        	String finishTime = req.getParameter("FinishTime");
        	String freezeTime = req.getParameter("FreezeTime");
        	String name = req.getParameter("Name");
        	log.warn("Name = " + name);
        	boolean fShowMaxMemory = null != req.getParameter("ShowMaxMemory");
        	boolean fShowMaxTime = null != req.getParameter("ShowMaxTime");
        	boolean fShowScore = null != req.getParameter("ShowScore");
        	boolean fShowTestingDetails = null != req.getParameter("ShowTestingDetails");
        	boolean fShowWrongTest = null != req.getParameter("ShowWrongTest");
        	boolean fShowFullMonitor = null != req.getParameter("ShowFullMonitor");
        	boolean fShowFullSubmissions = null != req.getParameter("ShowFullSubmissions");
        	String sid = req.getParameter("Sid");
        	String startTime = req.getParameter("StartTime");
        	String statementsLink = req.getParameter("StatementsLink");
        	String unfreezeTime = req.getParameter("UnfreezeTime");
        	boolean fVirtual = null != req.getParameter("Virtual");
        	boolean fEditAll = null != req.getParameter("EditAll");
        	if (fEditAll || null != req.getParameter("EditSid"))
        		contest.setSid(sid);
        	if (fEditAll || null != req.getParameter("EditName"))
        		contest.setName(name);
        	if (fEditAll || null != req.getParameter("EditContestType"))
        		contest.setContestType(contestType);
        	if (fEditAll || null != req.getParameter("EditStartTime"))
        		contest.setStartTime(Parsers.parseDate(startTime));
        	if (fEditAll || null != req.getParameter("EditFinishTime"))
        		contest.setFinishTime(Parsers.parseDate(finishTime));
        	if (fEditAll || null != req.getParameter("EditFreezeTime"))
        		contest.setFreezeTime(Parsers.parseDate(freezeTime));
        	if (fEditAll || null != req.getParameter("EditUnfreezeTime"))
        		contest.setUnfreezeTime(Parsers.parseDate(unfreezeTime));
        	if (fEditAll || null != req.getParameter("EditAllowAllLanguages"))
        		contest.setAllowAllLanguages(fAllowAllLanguages);
        	if (fEditAll || null != req.getParameter("EditAllowAllUsers"))
        		contest.setAllowAllUsers(fAllowAllUsers);
        	if (fEditAll || null != req.getParameter("EditAllowFirstTestOnly"))
        		contest.setAllowFirstTestOnly(fAllowFirstTestOnly);
        	if (fEditAll || null != req.getParameter("EditVirtual"))
        		contest.setVirtual(fVirtual);
        	if (fEditAll || null != req.getParameter("EditShowFullMonitor"))
        		contest.setShowFullMonitor(fShowFullMonitor);
        	if (fEditAll || null != req.getParameter("EditShowFullSubmissions"))
        		contest.setShowFullSubmissions(fShowFullSubmissions);
        	if (fEditAll || null != req.getParameter("EditShowWrongTest"))
        		contest.setShowWrongTest(fShowWrongTest);
        	if (fEditAll || null != req.getParameter("EditShowMaxTime"))
        		contest.setShowMaxTime(fShowMaxTime);
        	if (fEditAll || null != req.getParameter("EditShowMaxMemory"))
        		contest.setShowMaxMemory(fShowMaxMemory);
        	if (fEditAll || null != req.getParameter("EditShowTestingDetails"))
        		contest.setShowTestingDetails(fShowTestingDetails);
        	if (fEditAll || null != req.getParameter("EditShowScore"))
        		contest.setShowScore(fShowScore);
        	if (fEditAll || null != req.getParameter("EditStatementsLink"))
        		contest.setStatementsLink(statementsLink);
        	if (fVirtual && (fEditAll || null != req.getParameter("EditDuration")))
        		contest.setContestDuration(Long.parseLong(req.getParameter("Duration")));
        	
        	msg = contest.makePersistent() ? "OK" : "Failed"; 
        	returnToUrl = Linker.link("contests/admin/settings.jsp") + "?contest_id=" + id;
        }
        else if ("dataEdit".equalsIgnoreCase(action) && contest != null && model.canEdit(user))
        {
        	boolean result = true;
        	if (null != req.getParameter("doClearProblems"))
        	{
        		result &= contest.clearProblems();
        	}
        	if (null != req.getParameter("doClearUsers"))
        	{
        		result &= contest.clearUsers();
        	}
        	if (null != req.getParameter("doClearLanguages"))
        	{
        		result &= contest.clearLanguages();
        	}
        	if (null != req.getParameter("doClearSubmissions"))
        	{
        		result &= contest.crearSubmissions();
        	}
        	if (null != req.getParameter("doRejudgeSubmissions"))
        	{
        		result &= contest.rejudgeSubmissions();
        	}
        	msg = contest.makePersistent() ? "OK" : "Failed";
        	returnToUrl = Linker.link("contests/admin/data.jsp") + "?contest_id=" + id;
        }*/
	}

	@Override
	protected boolean processEdit(HttpServletRequest req, HttpServletResponse resp)
	{
		/*String contestSid = req.getParameter("sid");
		String contestName = req.getParameter("name");
		String contestActive = (null != req.getParameter("active")) ? "true" : "false";
		String startTime = req.getParameter("startTime");
		String finishTime = req.getParameter("finishTime");
		String freezeTime = req.getParameter("freezeTime");
		String type = req.getParameter("type");
		ContestsModel.editContest(id, contestSid, contestName, contestActive, startTime, finishTime, freezeTime, type);*/
        return true;
	}
}
